package com.neu.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.neu.App;
import com.neu.R;
import com.neu.bean.NewsBean;
import com.neu.util.VolleyUtil;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.VH> {

    private List<NewsBean.RowsBean> list;

    public NewsAdapter(List<NewsBean.RowsBean> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.fragement_news_adpter,null);
        return new VH(view);
    }

    @Override
    public void onBindViewHolder(@NonNull VH holder, int position) {
        NewsBean.RowsBean r=list.get(position);
        //holder.tvSubTitle.setText(r.getSubTitle().toString());
        holder.tvTitle.setText(r.getTitle());
        String url= VolleyUtil.BASE_URL+r.getCover();

        Glide.with(App.context).load(url).into(holder.imgNews);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class VH extends RecyclerView.ViewHolder{
        ImageView imgNews;
        TextView tvTitle;
        TextView tvSubTitle;

        public VH(@NonNull View itemView) {
            super(itemView);
            imgNews=itemView.findViewById(R.id.imgNews);
            tvTitle=itemView.findViewById(R.id.tvTitle);
            tvSubTitle=itemView.findViewById(R.id.tvSubTitle);
        }
    }
}
